import apiClient from '@/api/apiClient.ts';
import { OrderDetail, OrderInfo, ReporterInfo } from '#/entity.ts';
import { Page } from '#/api.ts';

export enum WorkOrderServicesApi {
  GetReporterList = '/roadCure/workOrder/getReportNameList',
  GetHeaderList = '/roadCure/workOrder/getHeaderList',
  GetTechnicianList = '/roadCure/workOrder/getTechnicianList',
  GetUserHeaderList = '/roadCure/workOrder/getUserHeaderList',
  GetList = '/roadCure/workOrder/getWorkOrderList',
  GetDetail = '/roadCure/workOrder/getWorkOrderDetails',
  Create = '/roadCure/workOrder/saveWorkOrder',
  Update = '/roadCure/workOrder/updateWorkOrder',
  ReportHandleResult = '/roadCure/workOrder/reportHandleResult',
}

export interface EditOrderParams {
  id?: number;
  alarmId: number;
  reportId: number;
  name: string;
  headId: number;
  beginTime: string;
  endTime: string;
  remarks?: string;
}

export interface OrderListParams {
  name?: string;
  companyUserIdList?: number[];
  companyHeadIdList?: number[];
  departmentIdList?: number[];
  alarmDesc?: string;
  reportPosition?: string;
  handleStatus?: boolean;
}

export interface ReportHandleResultParams {
  id: number;
  handleTime: string;
  notes: string;
  fileIdList: string[];
}

const getReporterList = () =>
  apiClient.get<ReporterInfo[]>({ url: WorkOrderServicesApi.GetReporterList });

const getHeaderList = () =>
  apiClient.get<ReporterInfo[]>({ url: WorkOrderServicesApi.GetHeaderList });

const getTechnicianList = () =>
  apiClient.get<ReporterInfo[]>({ url: WorkOrderServicesApi.GetTechnicianList });

const getUserHeaderList = () =>
  apiClient.get<ReporterInfo[]>({ url: WorkOrderServicesApi.GetUserHeaderList });

const getList = (data: OrderListParams & Page) =>
  apiClient.post<OrderInfo[]>({
    url: WorkOrderServicesApi.GetList,
    data,
  });

const getDetail = (id: number) =>
  apiClient.get<OrderDetail>({
    url: WorkOrderServicesApi.GetDetail,
    params: { id },
  });

const create = (data: Omit<EditOrderParams, 'id'>) =>
  apiClient.post({
    url: WorkOrderServicesApi.Create,
    data,
  });

const update = (data: EditOrderParams & { id: number }) =>
  apiClient.put({
    url: WorkOrderServicesApi.Update,
    data,
  });

const reportHandleResult = (data: ReportHandleResultParams) =>
  apiClient.post<Record<string, any>>({
    url: WorkOrderServicesApi.ReportHandleResult,
    data,
  });

export default {
  getReporterList,
  getHeaderList,
  getTechnicianList,
  getUserHeaderList,
  getList,
  getDetail,
  create,
  update,
  reportHandleResult,
};
